import cTitle from "components/title";
import yzWechatShareImg from "components/ui_components/yz_wechatShareImg";
export default {
  //name: 'login',
  data() {
    return {
      toi: this.fun.getKeyByI(),
      //追评
      append: null,
      //全部回复
      reply: null,
      //评价时间
      //主评论id
      comment_id: "",
      has_many_reply: [],
      has_one_order_goods: null,
      reply_placeholder: "回复@昵称:",
      //当前被回复对象
      reply_one: "",
      //1-代表回复主评论 2-回复某人
      reply_type: 1,
      images: [],
      // 评分
      worker_score: null, //安装师傅评分

      isShowShare: false,
      commentInfo:{},
    };
  },
  methods: {
    getNetData(status) {
      var that = this;
      $http
        .get(
          "goods.comment.get-order-goods-comment",
          {
            order_id: this.$route.params.order_id,
            goods_id: this.$route.params.goods_id,
            comment_id: this.$route.params.comment_id,
            order_goods_id: this.$route.params.order_goods_id,
            uid: this.$route.params.uid
          },
          "正在获取..."
        )
        .then(
          (response) => {
            if (response.result == 1) {
              var myData = response.data;
              this.commentInfo = response.data;
              this.append = myData.append;
              this.reply = myData.reply;
              this.has_one_order_goods = myData.has_one_order_goods;
              this.has_many_reply = myData.has_many_reply;
              this.comment_id = myData.id;
              this.images = myData.images;
              this.worker_score = myData.has_one_live_install_comment || {};
              this.worker_score.worker_name = myData.another_name ? myData.another_name.worker_name : "";
            } else {
              that.$dialog.alert({ message: response.msg });
            }
          },
          function(response) {
            // error callback
          }
        );
    },
    //触发回复动作
    replyToSomeOne(who) {
      this.reply_type = 2;
      this.reply_one = who;
      this.reply_placeholder = "回复@昵称:" + who.nick_name;
    },
    //回复主评论
    submitReplyForComment() {
      this.reply_type = 1;
      this.reply_placeholder = "回复@昵称:主评论";
    },
    //回复评价
    submitReply() {
      //goods.comment.reply-comment
      if (this.fun.isTextEmpty(this.reply_content)) {
        this.$toast('请输入回复内容');
        return false;
      }
      let reply_id;
      this.reply_type == 1?reply_id = this.comment_id:reply_id = this.reply_one.id;
      $http
        .get(
          "goods.comment.reply-comment",
          {
            id: reply_id,
            order_goods_id: this.commentInfo.order_goods_id,
            content: this.reply_content
          },
          "正在回复"
        )
        .then(
          (response) => {
            if (response.result == 1) {
              let myData = response.data;
              myData.is_shop = 0;
              this.reply_content = "";
              this.has_many_reply.push(myData);
              this.$toast(response.msg);
            } else {
              this.$dialog.alert({ message: response.msg });
            }
          },
          function(response) {
            // error callback
          }
        );
    },

    toGoods(goodsId) {
      this.$router.push(this.fun.getUrl("goods", { id: goodsId }));
    },
    // 分享
    showShareOverlay() {
      this.isShowShare = true;
    },
    initData() {
      this.content = "";
      this.created_at = "";
      this.append = "";
      this.reply = "";
      this.images = "";
      this.level = "";
      this.nick_name = "";
      this.level_name = "";
      this.has_one_order_goods = "";
      this.has_many_reply = "";
      this.comment_id = "";
      this.toi = this.fun.getKeyByI();
      this.getNetData();
      this.reply_placeholder = "回复@昵称:主评论";
    }
  },
  activated() {
    this.initData();
  },
  components: { cTitle, yzWechatShareImg }
};
